
// thread receive value
fn hello_thread(n: u32) {
    println!("hello from thread {n}");
}

// thread return value
fn do_math(i: u32) -> u32 {
    let mut n = i + 1;
    for _ in 0..10 {
        n *= 2;
    }
    n
}

fn main() {
    println!("Hello, world!");

    let mut thread_handles = Vec::new();
    
    for i in 0..10 {
        let thread_handle = std::thread::spawn(move || {
            hello_thread(i);
        });
        thread_handles.push(thread_handle);
    }

    // let thread_handle = std::thread::spawn(hello_thread);

    // thread_handle.join().unwrap();
    thread_handles.into_iter().for_each(|handle| handle.join().unwrap());

    let mut thread_handles = Vec::new();
    for i in 0..10 {
        let thread_handle = std::thread::spawn(move || {
            do_math(i)
        });
        thread_handles.push(thread_handle);
    }

    thread_handles.into_iter().for_each(|handle| {println!("{}",handle.join().unwrap())});

}
